import java.util.Random;
import java.util.Scanner;

public class Project02 {
    public static void main(String[] args) {
        // 生成随机数
        Random random = new Random();
        int secretNumber = random.nextInt(100) + 1;
        int attempts = 0;

        System.out.println("欢迎来到猜数字游戏！");
        System.out.println("我已经想好了一个1到100之间的整数，请开始猜测吧！");

        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.print("请输入你的猜测: ");
            int guess;

            // 验证输入是否为整数
            if (scanner.hasNextInt()) {
                guess = scanner.nextInt();
            } else {
                System.out.println("请输入有效的整数！");
                scanner.next(); // 清除无效输入
                continue;
            }

            // 验证输入范围
            if (guess < 1 || guess > 100) {
                System.out.println("请输入1到100之间的整数！");
                continue;
            }

            attempts++;

            if (guess == secretNumber) {
                // 猜对了，根据尝试次数给出评价
                String message;
                if (attempts == 1) {
                    message = "天才！一次就猜中了！";
                } else if (attempts <= 4) {
                    message = "太棒了！只用了" + attempts + "次就猜中了！";
                } else if (attempts <= 8) {
                    message = "不错！用了" + attempts + "次猜中。";
                } else {
                    message = "终于猜中了，用了" + attempts + "次。";
                }

                System.out.println("恭喜你猜对了！" + message);
                break;
            } else if (guess < secretNumber) {
                System.out.println("猜小了！再试一次。");
            } else {
                System.out.println("猜大了！再试一次。");
            }
        }

        scanner.close();
    }
}